package com.revenco.bi.dao.nutz;

import java.sql.Connection;
import javax.sql.DataSource;

import org.nutz.dao.ConnCallback;
import org.nutz.dao.impl.DaoRunner;
import org.springframework.jdbc.datasource.DataSourceUtils;


/**
 * 数据库操作的父类
 * * 
 * <pre>
 * -------------History------------------
 * DATE        AUTHOR    VERSION        DESCRIPTION
 * 2013-12-20   陈美燕                  V13.00.001      新增
 *
 *@author <a href="chenmeiyan@revenco.com">陈美燕</a>
 */
public class SpringDaoRunner implements DaoRunner {

	 public void run(DataSource dataSource, ConnCallback callback) {
	        Connection con = DataSourceUtils.getConnection(dataSource);
	        try {
	            callback.invoke(con);
	        }
	        catch (Exception e) {
	            if (e instanceof RuntimeException)
	                throw (RuntimeException) e;
	            else
	                throw new RuntimeException(e);
	        } finally {
	            DataSourceUtils.releaseConnection(con, dataSource);
	        }
	    }

}
